<?php
//用餐记录

namespace App\Repositories\Filter;

use App\Models\DinnerLogModel;

class DinnerLogFilter
{
    /**
     * 处理查询条件
     * @param $query
     * @return array[]
     */
    public static function handleQuery($query = [])
    {
        $where = [];
        $whereIn = [];
        $tableName = (new DinnerLogModel())->getTable();

        if (!empty($query['activity_id'])) {
            $where[] = ['activity_id', $query['activity_id']];
        }
        if (!empty($query['activity_ids'])) {
            $whereIn[] = ['activity_id', $query['activity_ids']];
        }
        if (!empty($query['restaurant_id'])) {
            $where[] = ['restaurant_id', $query['restaurant_id']];
        }
        if (!empty($query['restaurant_ids'])) {
            $whereIn[] = ['restaurant_id', $query['restaurant_ids']];
        }
        if (!empty($query['created_at_gte'])) {
            $where[] = ['created_at', '>=', $query['created_at_gte']];
        }
        if (!empty($query['created_at_lt'])) {
            $where[] = ['created_at', '<', $query['created_at_lt']];
        }
        if (!empty($query['created_at_lte'])) {
            $where[] = ['created_at', '<=', $query['created_at_lte']];
        }
        if (!empty($query['type'])) {
            $where[] = ['type', $query['type']];
        }
        if (!empty($query['receiver_id'])) {
            $where[] = ['receiver_id', $query['receiver_id']];
        }
        if (!empty($query['money'])) {
            $where[] = ['money', $query['money']];
        }
        if (!empty($query['settlement_status'])) {
            $where[] = ['settlement_status', $query['settlement_status']];
        }

        foreach ($where as &$val) {
            $val[0] = $tableName.'.'.$val[0];
        }
        unset($val);
        foreach ($whereIn as &$val) {
            $val[0] = $tableName.'.'.$val[0];
        }
        unset($val);

        return [
            'where'   => $where,
            'whereIn' => $whereIn,

        ];
    }


}